﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;

namespace MyMeeting.Common
{
    public class ImgButton:Button
    {
      //  public ImageSource ImgPath { get; set; }
        public ImageSource HoverImgPath { get; set; }

        public ImageSource ImgPath
        {
            get { return (ImageSource)GetValue(ImgPathProperty); }
            set { SetValue(ImgPathProperty, value); }
        }

        // Using a DependencyProperty as the backing store for ImgPath.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty ImgPathProperty =
            DependencyProperty.Register("ImgPath", typeof(ImageSource), typeof(ImgButton));

        //public ImageSource HoverImgPath
        //{
        //    get { return (ImageSource)GetValue(HoverImgPathProperty); }
        //    set { SetValue(HoverImgPathProperty, value); }
        //}

        //// Using a DependencyProperty as the backing store for ImgPath.  This enables animation, styling, binding, etc...
        //public static readonly DependencyProperty HoverImgPathProperty =
        //    DependencyProperty.Register("HoverImgPath", typeof(ImageSource), typeof(ImgButton));

        //public string HoverImgPath
        //{
        //    get { return (string)GetValue(HoverImgPathProperty); }
        //    set { SetValue(HoverImgPathProperty, value); }
        //}

        //// Using a DependencyProperty as the backing store for ImgPath.  This enables animation, styling, binding, etc...
        //public static readonly DependencyProperty HoverImgPathProperty =
        //    DependencyProperty.Register("HoverImgPath", typeof(string), typeof(ImgButton));

        public CornerRadius Radius
        {
            get { return (CornerRadius)GetValue(RadiusProperty); }
            set { SetValue(RadiusProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Radius.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty RadiusProperty =
            DependencyProperty.Register("Radius", typeof(CornerRadius), typeof(ImgButton));
        
        protected override void OnMouseEnter(MouseEventArgs e)
        {
            base.OnMouseEnter(e);
            if(HoverImgPath != null)
            {
                var temp = ImgPath;
                ImgPath = HoverImgPath;
                HoverImgPath = temp;
                temp = null;
            }
        }
        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            if (HoverImgPath != null)
            {
                var temp = ImgPath;
                ImgPath = HoverImgPath;
                HoverImgPath = temp;
                temp = null;
            }
        }
    }
}
